/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Advertentie;
import org.hibernate.Session;
import org.hibernate.Transaction;
import persistence.SessionManager;

/**
 *
 * @author Johan
 */
public class AdvertentieEditController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        System.out.println("-----------------------> AdvertentieEditController - doGet - begin");
        int advId = Integer.parseInt(request.getParameter("advId"));

        Session session = null;
        session = SessionManager.openSession();

        Transaction tx = session.beginTransaction();
        Advertentie advertentie = (Advertentie) session.load(Advertentie.class, new Integer(advId));

        request.setAttribute("advertentie", advertentie);
        // http:\\ verwijderen van website string
//        String shortWebsite = advertentie.getAdvWebsite().substring(7);
//        request.setAttribute("advwebsite", shortWebsite);
        

        System.out.println("-----------------------> AdvertentieEditController - doGet - einde");
        String address = "/adverteerToevoegen.jsp";
        RequestDispatcher dispatcher = request.getRequestDispatcher(address);
        dispatcher.forward(request, response);
        
        session.close();
    }
    
}
